﻿using FinancialBook.Core.Service;
using FinancialBook.Models;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace FinancialBook.Core.ViewModels
{
    public class TransactionViewModel : MvxViewModel
    {
        public ObservableCollection<Transaction> ListTransaction { get; set; }
        ITransactionRepository context;
        ICategoryRepository contextC;

        public TransactionViewModel()
        {
            ListTransaction = new ObservableCollection<Transaction>();
            context = Mvx.Resolve<ITransactionRepository>();
            contextC = Mvx.Resolve<ICategoryRepository>();
            GetAllData();
        }

        public ICommand ShowNewTransaction
        {
            get
            {
                return new MvxCommand(() =>
                {
                    ShowViewModel<TransactionNewViewModel>();
                });
            }
        }

        public ICommand ShowCategory
        {
            get
            {
                return new MvxCommand(() =>
                {
                    ShowViewModel<CategoryViewModel>();
                });
            }
        }

        private void GetAllData()
        {
            var trans = context.AllItems();
            var cats = contextC.AllItems();
            foreach (var item in trans)
            {
                if (!ListTransaction.Contains(item))
                {
                    ListTransaction.Add(item);
                }
            }
        }
    }
}